#include "common.h"

namespace Opl{ namespace Gui{ namespace Common{

            QMatrix4x4 fromRotation(float angle, Qt::Axis axis)
            {
                QMatrix4x4 m;
                if (axis == Qt::XAxis)
                    m.rotate(angle, QVector3D(1, 0, 0));
                else if (axis == Qt::YAxis)
                    m.rotate(-angle, QVector3D(0, 1, 0));
                else if (axis == Qt::ZAxis)
                    m.rotate(angle, QVector3D(0, 0, 1));
                return m;
            }

            QMatrix4x4 fromProjection(float fovAngle)
            {
                float fov = qCos(fovAngle / 2) / qSin(fovAngle / 2);

                float zNear = 0.01;
                float zFar = 1000;

                float m33 = (zNear + zFar) / (zNear - zFar);
                float m34 = (2 * zNear * zFar) / (zNear - zFar);

                qreal data[] =
                {
                    fov, 0, 0, 0,
                    0, fov, 0, 0,
                    0, 0, m33, m34,
                    0, 0, -1, 0
                };
                return QMatrix4x4(data);
            }

            QTransform rotatingTransform(qreal angle)
            {
                QTransform transform;
                transform.rotate(angle);
                return transform;
            }
}}}
